package com.tarena.test.luban.demo.rpc.demo01.client.service;

import com.tarena.test.luban.demo.rpc.demo01.server.service.People;

import java.io.*;
import java.net.Socket;

public class PeopleProxy implements People {
    @Override
    public String sayHi(String name) throws IOException {
        //建立一个链接 127.0.0.1:20000
        Socket socket=new Socket("192.168.56.1",20000);
        //拿到当前socket的数据
        OutputStream outputStream = socket.getOutputStream();
        DataOutputStream dos=new DataOutputStream(outputStream);
        //dos输出字符数据 过程涉及到 java序列化
        dos.writeUTF(name);
        //刷出缓存
        dos.flush();
        //不仅仅输出 到server 还可以接收server返回数据
        InputStream inputStream = socket.getInputStream();
        DataInputStream dis=new DataInputStream(inputStream);
        //返序列化将server数据解析
        String result = dis.readUTF();
        System.out.println("服务端返回:"+result);
        return result;
    }

    @Override
    public void eat(String name) throws IOException {

    }
}
